<?php
namespace App\Model;
use PhalApi\Model\DataModel;

class MirCategoryList extends DataModel {

    protected function getTableName($id) {
        return 'game_category_list';
    }

    //插入数据
    public function selectByCategoryList($data) {
        $rides = \PhalApi\DI()->cache->get( $data->Category."|".$data->CategoryTitle);
        if( $rides ){
//            return $rides;
        }
        $list = $this->getORM()->where(
            array(
                'Category' => $data->Category,
                'CategoryTitle'=> $data->CategoryTitle
            ))->fetchAll();

        \PhalApi\DI()->cache->set( $data->Category."|".$data->CategoryTitle,$list,60*24*60*60 );
        return $list;
    }

    //插入数据
    public function insertCategoryList($data) {
        return $this->getORM()->insert($data);
    }

    //插入数据
    public function selectByWhere($json) {
        $where = array();
        $where['Category'] = $json['Category'];
        $where['CategoryTitle'] = $json['CategoryTitle'];
        $where['PageName'] = $json['PageName'];

        $list = $this->getORM()->where( $where )->fetchOne();
        return $list ? $list : $this->insertCategoryList($json);
    }

}
